<script
  type="text/javascript"
  src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"
></script>
<script src="../../layuiadmin/layui/layui.js"></script>
<script>
  layer.photos({
    photos: ".layer-photos-demo",
    anim: 5, //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
  });
  function open_add(title, url) {
    if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
      layer.open({
        type: 2,
        title: title,
        content: url,
        area: ["95%", "95%"],
        maxmin: true,
      });
    } else {
      layer.open({
        type: 2,
        title: title,
        content: url,
        area: ["70%", "95%"],
        maxmin: true,
      });
    }
  }
  /*数据-删除*/
  function open_dels(obj, url, id) {
    layer.confirm("确认要执行该操作吗？", function (index) {
      //发异步删除数据
      $.post(
        url,
        { id: id },
        function (data) {
          if (data.status == 0) {
            $(obj).parents("tr").remove();
            $("#count").text($("#count").text() - 1);
            layer.msg(data.msg, { icon: 1, time: 1000 });
          } else {
            layer.msg(data.msg, { icon: 2, time: 1000 });
          }
        },
        "json"
      );
    });
  }
  /*数据-删除*/
  function open_dels2(obj, url, id) {
    layer.confirm("确认要执行该操作吗？", function (index) {
      //发异步删除数据
      $.post(
        url,
        { id: id },
        function (data) {
          if (data.status == 0) {
            layer.msg(data.msg, { icon: 1, time: 1000 }, function () {
              // 获得frame索引
              location.reload();
              layer.close(index);
            });
          } else {
            layer.msg(data.msg, { icon: 2, time: 1000 });
          }
        },
        "json"
      );
    });
  }
  /*数据-删除*/
  function open_status(obj, url, id, status) {
    layer.confirm("确认要执行该操作吗？", function (index) {
      //发异步删除数据
      $.post(
        url,
        { id: id, status: status },
        function (data) {
          if (data.status == 0) {
            $(obj).parents("tr").remove();
            $("#count").text($("#count").text() - 1);
            layer.msg(data.msg, { icon: 1, time: 1000 });
          } else {
            layer.msg(data.msg, { icon: 2, time: 1000 });
          }
        },
        "json"
      );
    });
  }

  function promt_alert(title, url, id) {
    layer.prompt(
      {
        formType: 0,
        title: title,
      },
      function (value, index, elem) {
        $.post(
          url,
          { id: id, value: value },
          function (data) {
            if (data.status == 0) {
              layer.msg(data.msg, { icon: 6, time: 1000 }, function () {
                // 获得frame索引
                location.reload();
                layer.close(index);
              });
            } else {
              layer.msg(data.msg, { icon: 2, time: 1000 });
            }
          },
          "json"
        );
      }
    );
  }

  function open_alert(title, url, id, status) {
    layer.open({
      type: 0,
      title: title,
      btn: ["确认", "关闭"],
      content:
        '<div class="layui-card-body layui-row layui-col-space10"><div class="layui-col-md12"><input type="text" name="value1" class= "layui-input"  placeholder = "请填写配送物流名称,如:韵达快递"></div ></div><div class="layui-card-body layui-row layui-col-space10"><div class="layui-col-md12"><input type="text" name="value2" class= "layui-input"  placeholder = "请填写配送物流单号,如:5897351682"></div></div >',
      yes: function (value, index, elem) {
        var value1 = $("input[name='value1']").val();
        var value2 = $("input[name='value2']").val();
        if (!value1) {
          layer.msg("请填写物流名称", { icon: 2, time: 1000 });
          return false;
        }
        if (!value2) {
          layer.msg("请填写物流编号", { icon: 2, time: 1000 });
          return false;
        }
        $.post(
          url,
          { id: id, value: value1, value2: value2, status: 3 },
          function (data) {
            if (data.status == 0) {
              layer.msg(data.msg, { icon: 6, time: 1000 }, function () {
                // 获得frame索引
                location.reload();
                layer.close(index);
              });
            } else {
              layer.msg(data.msg, { icon: 2, time: 1000 });
            }
          },
          "json"
        );
      },
    });
  }
</script>
